<?php
/* SVN FILE: $Id: team.php 250 2010-06-17 10:55:41Z gregory.rome $ */
/**
 * Model.
 *
 * @todo Add file description.
 *
 * cBBweb : Digital Blood Bowl league interface (http://code.google.com/p/cbbweb/)
 * Copyright 2009-2010, Grégory Romé.
 *
 * Licensed under The MIT License
 * Redistributions of files must retain the above copyright notice.
 *
 * @filesource
 * @copyright     Copyright 2009-2010, Grégory Romé.
 * @link          http://code.google.com/p/cbbweb/ cBBweb Project
 * @package       cbbweb
 * @subpackage    cbbweb.models
 * @version       $Revision: 250 $
 * @modifiedby    $LastChangedBy: gregory.rome $
 * @lastmodified  $Date: 2010-06-17 10:55:41 +0000 (Thu, 17 Jun 2010) $
 * @license       http://www.opensource.org/licenses/mit-license.php The MIT License
 */

/**
 * Model.
 *
 * @todo Add model description.
 *
 * @package       cbbweb
 * @subpackage    cbbweb.models
 */
class Team extends AppModel {

	var $name = 'Team';
	var $primaryKey = 'ID';
	var $useTable = 'team_listing';

	/**
	 * Allow to retrieve race name and coach name.
	 */
	var $belongsTo = array(
		'Race' => array(
			'className' => 'Race',
			'foreignKey' => 'idRaces',
			'fields' => array('Race.ID, Race.idStrings_Localized, Race.iRerollPrice'),
		),
		'Coach' => array(
			'className' => 'Coach',
			'foreignKey' => 'idCoach',
			'fields' => array('Coach.ID, Coach.strName'),
		)
	);

    var $hasMany = array(
        'Player' => array(
            'className'     => 'Player',
            'foreignKey'    => 'idTeam_Listing',
            'dependent'=> true
        ),
        'StatisticsSeasonTeam' => array(
            'className'     => 'StatisticsSeasonTeam',
            'foreignKey'    => 'idTeam_Listing',
            'dependent'=> true
        ),
    );

    var $hasOne = array(
        'StatisticsTeam' => array(
            'className'     => 'StatisticsTeam',
            'foreignKey'    => 'idTeam_Listing',
            'dependent'=> true
        ),
        'StatisticsCurrentSeasonTeam' => array(
            'className'   => 'StatisticsSeasonTeam',
            'foreignKey'  => 'idTeam_Listing',
            'conditions'	=> array('StatisticsCurrentSeasonTeam.bFinished' => 0),
            'dependent'=> false
        ),
    );

	var $hasAndBelongsToMany = array(
		'Championship' => array(
			'className' => 'Championship',
			'joinTable' => 'championship_has_teams',
			'foreignKey' => 'idTeam',
			'associationForeignKey' => 'idChampionship',
			'unique' => true
		)
	);

}
?>
